<template>
  <div class="student-layout">
    <NavBar />
    <div class="student-container">
      <div class="student-sidebar">
        <h3 class="sidebar-title">学生学习中心</h3>
        <ul class="sidebar-menu">
          <li>
            <router-link to="/student/dashboard" active-class="active">
              <i class="el-icon-dashboard"></i>
              <span>学习进度</span>
            </router-link>
          </li>
          <li>
            <router-link to="/student/errors" active-class="active">
              <i class="el-icon-error"></i>
              <span>错题本</span>
            </router-link>
          </li>
<!--          <li>-->
<!--            <router-link to="/student/assessment" active-class="active">-->
<!--              <i class="el-icon-chart"></i>-->
<!--              <span>能力评估</span>-->
<!--            </router-link>-->
<!--          </li>-->
          <li>
            <router-link to="/student/assistant" active-class="active">
              <i class="el-icon-chat"></i>
              <span>AI助手</span>
            </router-link>
          </li>
          <li>
            <router-link to="/student/practice" active-class="active">
              <i class="el-icon-edit"></i>
              <span>练习学习</span>
            </router-link>
          </li>
<!--          <li>-->
<!--            <router-link to="/student/history" active-class="active">-->
<!--              <i class="el-icon-time"></i>-->
<!--              <span>历史记录</span>-->
<!--            </router-link>-->
<!--          </li>-->
        </ul>
      </div>
      <div class="student-content">
        <router-view></router-view>
      </div>
    </div>
  </div>
</template>

<script setup>
import NavBar from '@/components/NavBar.vue';
import { useRouter } from 'vue-router';
import { onMounted } from 'vue';

const router = useRouter();

onMounted(() => {
  // 检查用户是否为学生
  const userRole = localStorage.getItem('userRole');
  if (userRole !== '2') {
    // 如果不是学生，重定向到合适的页面
    if (userRole === '1') {
      router.push('/design/new'); // 教师首页
    } else {
      router.push('/'); // 默认首页
    }
  }
});
</script>

<style scoped>
.student-layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background-color: #f5f7fa;
}

.student-container {
  display: flex;
  flex: 1;
  margin-top: 60px; /* 导航栏高度 */
}

.student-sidebar {
  width: 240px;
  background-color: #ffffff;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  padding: 20px 0;
  height: calc(100vh - 60px);
  position: fixed;
  top: 60px;
  left: 0;
  overflow-y: auto;
}

.sidebar-title {
  font-size: 18px;
  color: #1a73e8;
  padding: 0 20px;
  margin-bottom: 20px;
  border-left: 4px solid #1a73e8;
}

.sidebar-menu {
  list-style: none;
  padding: 0;
  margin: 0;
}

.sidebar-menu li {
  margin-bottom: 5px;
}

.sidebar-menu li a {
  display: flex;
  align-items: center;
  padding: 15px 20px;
  color: #606266;
  text-decoration: none;
  transition: all 0.3s;
}

.sidebar-menu li a i {
  margin-right: 10px;
  font-size: 18px;
}

.sidebar-menu li a:hover {
  color: #1a73e8;
  background-color: #f0f7ff;
}

.sidebar-menu li a.active {
  color: #1a73e8;
  background-color: #f0f7ff;
  border-right: 4px solid #1a73e8;
  font-weight: 600;
}

.student-content {
  flex: 1;
  padding: 20px;
  margin-left: 240px; /* 侧边栏宽度 */
}

@media (max-width: 768px) {
  .student-sidebar {
    width: 200px;
  }
  
  .student-content {
    margin-left: 200px;
  }
}
</style> 